<!--
 * @FilePath     : /study_code/layui/10-32.html
 * @Description  : onClickOutside 点击 dropdown 外部时的回调函数
 * @Date         : 2025-04-09 10:34:32
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-09 10:58:03
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
  </head>
  <body>
    <div class="layui-btn-container">
      <button
        class="layui-btn layui-btn-primary demo-dropdown-align"
        lay-options="{align: 'center'}"
      >
        居中对齐
        <i class="layui-icon layui-icon-down layui-font-12"></i>
      </button>
    </div>

    <script src="/layui/dist/layui.js"></script>
    <script src="/dropdown/common.js"></script>
    <script>
      layui.use(function () {
        var dropdown = layui.dropdown
        // 水平对齐方式
        dropdown.render({
          elem: '.demo-dropdown-align',

          data: data0,

          /**
           * @brief: 点击 dropdown 外部时的回调函数，
           * @param {*} elem:当前点击的事件对象
           * @return {*}
           * 返回 false 可阻止关闭。
           */
          onClickOutside: function (event) {
            console.log(1, event)
            return false // 返回 false，当点击面板外部时可阻止关闭
          },
        })
      })
    </script>
  </body>
</html>
